<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>模板管理</title>
    <link rel="stylesheet" href="/static/assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="/static/assets/libs/codemirror/codemirror.css">
    <link rel="stylesheet" href="/static/assets/libs/codemirror/darcula.css">
    <!--[if lt IE 9]>
   <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
   <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
   -->
   <style>
       #runjsParent #runjs{
           height: 540px;
           width: 100%;
       }
       #runjs .layui-row {
           height: 100%;
           width: 100%;
           overflow: hidden;
       }
       #runjs .layui-row>div{
           height: 100%;
           overflow: auto;
           position: relative;
       }
       #runjs .site-demo-btn1 {
           position: absolute;
           bottom: 15px;
           right: 20px;
           z-index: 10000;
       }
       #runjs .site-demo-btn2 {
           position: absolute;
           bottom: 15px;
           right: 120px;
           z-index: 10000;
       }
       #runjs .CodeMirror {
           width: 100%;
           height: 100%;
       }
       #runjsDemo {
           width: 90%;
           height: 90%;
           border: none;
           padding: 10px;
       }
       k{
           color: #d63200;
           padding: 3px 5px;
           margin: 0 2px;
           border-radius: 2px;
           white-space: nowrap;
           font-size: 0.85em;
           background-color: #f8f8f8;
           -webkit-font-smoothing: initial;
       }
   </style>
</head>
<body>
   <!--代码编辑-->
<div id="runjsParent">
    <div id="runjs">
        <div class="layui-row">
            <div class="layui-col-xs8">
                <input id="codePageId" type="hidden"/>
                <textarea id="code"></textarea>
                <div class="site-demo-btn2">
                    <a type="button" class="layui-btn" id="template_save">保存</a>
                </div>
                <div class="site-demo-btn1">
                    <a type="button" class="layui-btn" id="demo_run">测试预览</a>
                </div>
            </div>
            <div class="layui-col-xs4">
                <div style="position: relative;margin: 0 auto;padding: 0 15px;box-sizing: border-box;line-height: 1.4r
">
                    模板语法<br>
                    <strong>全局属性</strong><br>
                    tplCategory：模版分类<br>
                    tableName：表名<br>
                    ClassName：实体类大写<br>
                    className：实体类小写<br>
                    moduleName：模块名称<br>
                    businessName：业务名<br>
                    packageName：包名（带模块包名）<br>
                    author：作者<br>
                    date：生成时间<br>
                    pkColumn：主键<br>
                    columns：所有字段<br>
                    dbType：数据库类型<br>
                    table：表数据<br>
                    needLog：开启日志<br>
                    needPerm：开启权限<br>
                    needSwagger：开启swagger<br>
                    <strong>列属性</strong><br>
                    columnName：列名称<br>
                    columnComment：列描述<br>
                    columnType：列类型<br>
                    javaType：JAVA类型<br>
                    javaField：JAVA字段名<br>
                    pk：是否主键<br>
                    increment：是否自增（1是）<br>
                    required：是否必填（1是）<br>
                    insert：是否为插入字段（1是）<br>
                    edit：是否编辑字段（1是）<br>
                    list：是否列表字段（1是）<br>
                    query：是否查询字段（1是）<br>
                    queryType：查询方式（EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围）<br>
                    htmlType：显示类型（input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件）<br>
                    sort：排序<br>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- js部分 -->
<script type="text/javascript" src="/static/assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="/static/assets/js/common.js?v=318"></script>
<!-- codmirror部分 -->
<script type="text/javascript" charset="utf-8" src="/static/assets/libs/codemirror/codemirror.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/assets/libs/codemirror/selection-pointer.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/assets/libs/codemirror/xml.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/assets/libs/codemirror/javascript.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/assets/libs/codemirror/htmlmixed.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/assets/libs/codemirror/css.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/assets/libs/codemirror/clike.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/assets/libs/codemirror/velocity.js"></script>
<script>
    layui.use(['layer', 'form', 'table', 'util', 'admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;
        var template = admin.getLayerData().template;
        $('#runjs .CodeMirror').remove();

        window.editor = CodeMirror.fromTextArea(document.getElementById("code"), {
            mode: "text/velocity",
            // 显示行号
            lineNumbers: true,
            // 括号匹配
            matchBrackets: true,
            theme: "darcula",
            tabSize: 4,
            //lineWrapping: true,
            selectionPointer: true
        });
        //var ifr = document.getElementById("runjsDemo");
        window.editor.setValue(template.content || '');

        $('#template_save').on('click',function (e) {
            template.content = window.editor.getValue();
            $.ajax({
                url: '/template/',
                data: JSON.stringify(template),
                dataType: 'json',
                method: template ? 'PUT' : 'POST',
                contentType: 'application/json;charset=utf-8',
                success: function (res) {
                    if (0 === res.code) {
                        layer.msg(res.msg, {icon: 1});
                        admin.putLayerData('formOk', true);  // 设置操作成功的标识
                        admin.closeThisDialog();  // 关闭当前iframe弹窗
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }
            });
        })

    });
</script>

</body>
</html>
